home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 4 code / Poly. in Code Resources / A5World / A5World.cp next >
Encoding:
Text File  |  1990-08-16  |  1.6 KB  |  83 lines  |  [TEXT/MPS ]

  1. /*
  2.     A5World.cp
  3.     
  4.     Implementation of A5 world maintenance class.
  5.     
  6.     This class maintains an A5 global space.
  7.     
  8.     by Patrick Beard.
  9.     
  10.     based on TN 256.
  11.  
  12.     ©1990 by Patrick C. Beard.  All rights reserved.
  13.  */
  14.  
  15. #ifndef __A5WORLD__
  16. #include "A5World.h"
  17. #endif
  18.  
  19. #ifndef __QUICKDRAW__
  20. #include <QuickDraw.h>
  21. #endif
  22.  
  23. extern "C" {
  24. void A5Init(Ptr);        // function that sets up (initializes) the A5 world.
  25. long A5Size(void);        // function that returns the size of our A5 world.
  26. void init_vtbls(void);    // function that initializes virtual tables.
  27. }
  28.  
  29. // utility routine to switch A5's.  (lifted from OSUtils.h)
  30. pascal Ptr SwapA5(Ptr newA5)
  31.     = {0x2F4D,0x0004,0x2A5F};
  32.  
  33. // constructor:  set up the current App's required A5 world.
  34.  
  35. A5World::A5World()
  36. {
  37.     error = noErr;                                // default is no error.
  38.     oldA5 = nil;                                // none established for them.
  39.     worldSize = A5Size();                        // store our size for speed.
  40.     ourA5 = NewPtr(worldSize);                    // better not fail.
  41.     if(!ourA5) {
  42.         error = -1;
  43.         return;
  44.     }
  45.     
  46.     // initialize our globals.
  47.     A5Init(ourA5 + worldSize - 32);                // see TN 256.
  48.     
  49.     // call InitGraf to initialize quickdraw globals.
  50.     GrafPtr aPort;
  51.     GetPort(&aPort);
  52.     Enter();                                    // go inside our world.
  53.     InitGraf(&qd.thePort);
  54.     SetPort(aPort);
  55.     
  56.     Leave();                                    // leave the virtual world.
  57. }
  58.  
  59. A5World::~A5World()
  60. {
  61.     Leave();                                    // restore any saved A5.
  62.     if(ourA5)
  63.         DisposPtr(ourA5);
  64. }
  65.  
  66. void A5World::Enter()
  67. {
  68.     GrafPtr currPort;
  69.     GetPort(&currPort);
  70.  
  71.     oldA5 = SwapA5(ourA5 + (worldSize - 32));
  72.     
  73.     SetPort(currPort);
  74. }
  75.  
  76. void A5World::Leave()
  77. {
  78.     if(oldA5) {
  79.         SwapA5(oldA5);
  80.         oldA5 = nil;                            // clear it so we won't do it again.
  81.     }
  82. }
  83.